package com.tyut.listener;

import com.tyut.domain.TagDocument;
import com.tyut.service.SearchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 标签索引监听器
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TagIndexListener {

    private final SearchService searchService;

    /**
     * 监听标签创建/更新消息
     *
     * @param document 标签文档
     */
    @RabbitListener(queues = "tag.index.queue")
    public void handleTagIndex(TagDocument document) {
        log.info("收到标签索引消息: {}", document);
        boolean result = searchService.indexTag(document);
        log.info("标签索引结果: {}", result);
    }

    /**
     * 监听标签删除消息
     *
     * @param id 标签ID
     */
    @RabbitListener(queues = "tag.delete.queue")
    public void handleTagDelete(String id) {
        log.info("收到标签删除消息: {}", id);
        boolean result = searchService.deleteTag(id);
        log.info("标签删除结果: {}", result);
    }
} 